package com.pgybook.front.web.util;

import jodd.http.HttpUtil;
import jodd.http.HttpValuesMap;
import jodd.util.StringPool;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: feeling
 * Date: 13-11-21
 * Time: 下午3:52
 */
public abstract class FrontUtil {
    public static final String CUSTOMER_KEY = "cust";
    public static final String CUSTOMER_ID_KEY = "custId";

    public static String actionSuffix = ".jspx";
    public static String pageSuffix = "";

    public static String page(String page) {
        return page + pageSuffix;
    }

    public static String action(String action) {
        return action + actionSuffix;
    }

    public static String redirectAction(String action) {
        return "redirect:" + action + actionSuffix;
    }

    public static String redirectPage(String page) {
        return "redirect:" + page + pageSuffix;
    }

    public static String redirectPage(String page, Map<String, Object> params) {
        HttpValuesMap hvm = new HttpValuesMap();
        for (String s : params.keySet()) {
            hvm.add(s, params.get(s));
        }
        return "redirect:" + page + pageSuffix + "?" + HttpUtil.buildQuery(hvm, StringPool.UTF_8);
    }
}
